#include<opencv2/opencv.hpp>
#include<iostream>

using namespace cv;
using namespace std;


int main()
{
    Mat img=imread("/home/lwj/opencv.21/2.png");
    Mat out,imgv,imgg,put;
    cvtColor(img,imgg,COLOR_BGR2GRAY);
    threshold(imgg,imgv,50,255,THRESH_BINARY);//二值化
    //开运算 先腐蚀再膨胀
    Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));
    morphologyEx(imgv,out,2,kernel);
    namedWindow("open",WINDOW_AUTOSIZE);
    imshow("open",out);
    //闭运算 先膨胀再腐蚀
    morphologyEx(imgv,put,3,kernel);
    namedWindow("close",WINDOW_AUTOSIZE);
    imshow("close",put);
    waitKey(0);
    return 0;
}